<template>
  <div id="playBackTopSearch">
    <h1 class="con-right-title">
      回放视频评论审核
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="人审结果" prop="peopleAuditStatus">
          <el-select
            v-model="formInline.peopleAuditStatus"
            clearable
            placeholder=""
          >
            <el-option
              v-for="item in pExamineList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机审结果" prop="machineAuditStatus">
          <el-select
            v-model="formInline.machineAuditStatus"
            clearable
            placeholder=""
          >
            <el-option
              v-for="item in mExamineList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-select v-model="formInline.sort" placeholder="">
            <el-option
              v-for="item in orderList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="timeType">
          <el-select v-model="formInline.timeType" placeholder="">
            <el-option
              v-for="item in timeTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            class="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="查询" prop="searchText">
          <el-input
            clearable
            v-model="formInline.searchText"
            placeholder="请输入评论内容搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="审核人" prop="checkUserId">
          <el-select
            v-model="formInline.checkUserId"
            placeholder=""
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户搜索" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入相应的搜索内容"
          >
            <el-select
              slot="prepend"
              v-model="formInline.userType"
              placeholder="请选择"
            >
              <el-option label="大鹏号" value="dpAccount"></el-option>
            </el-select>
          </el-input>
        </el-form-item>
        <el-form-item label="用户属性" prop="userProperty">
          <el-select v-model="formInline.userProperty" clearable>
            <el-option
              v-for="item in userAttList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getCreateTime } from '@utils/pubFunction'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'playBackTopSearch',
  msg: '评论审核-回放视频评论审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          peopleAuditStatus: '', // 人审结果
          machineAuditStatus: '', // 机审结果
          sort: '', // 顺序
          timeType: '', // 顺序2
          checkUserId: '', // 审核人
          workType: '', // 作品类型
          searchText: '', // 查询评论内容
          maxDate: '',
          minDate: '',
          startTime: '',
          endTime: '',
          userProperty: '', // 用户属性
          dpAccount: '',
          userType: 'dpAccount'
        }
      }
    }
  },
  data() {
    return {
      pExamineList: [
        // 人审结果
        { dictLabel: '所有', dictValue: '' }
      ],
      mExamineList: [
        // 机审结果
        { dictLabel: '所有', dictValue: '' }
      ],
      // 排序
      orderList: [],
      timeTypeList: [],
      personList: [
        // 审核人
        { nickname: '所有', dapengUserId: '' }
      ],
      userAttList: [{ dictLabel: '全部', dictValue: '' }], // 用户属性
      rules: {
        peopleAuditStatus: {},
        machineAuditStatus: {},
        sort: {},
        timeType: {},
        workType: {},
        checkUserId: {},
        userProperty: {},
        searchText: {}
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },

  mounted() {
    this.getStatusList()
    this.getCheckUser()
  },
  methods: {
    getCreateTime() {
      const createTime = getCreateTime()
      this.formInline.createTime = createTime
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.getCreateTime()
      this.setDefaultValue()
    },
    /* 获取数据状态 */
    async getStatusList() {
      // 共用接口-人审结果/机审结果
      let examineList = await sysNormalDisable('sys_audit_status', 'result')
      this.pExamineList = this.pExamineList.concat(examineList)
      this.mExamineList = this.mExamineList.concat(examineList)
      // 排序
      this.orderList = await sysNormalDisable('sys_audit_time_type')
      // 时间类型
      this.timeTypeList = await sysNormalDisable('sys_audit_search_type')
      // 用户属性
      let UserAttr = await sysNormalDisable(
        'comment_user_attributes',
        'checkUserAttr'
      )
      this.userAttList = this.userAttList.concat(UserAttr)
      this.setDefaultValue()
      this.$emit('toSearch')
    },
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    },
    setDefaultValue() {
      this.formInline.sort = this.orderList[0].dictValue
      this.formInline.timeType = this.timeTypeList[0].dictValue
    }
  }
}
</script>

<style lang="less">
#playBackTopSearch {
  .el-input {
    &.el-input--suffix {
      width: 182px !important;
    }
  }
  .datetimerange {
    margin-left: -16px;
  }
  label.el-form-item__label {
    width: 70px !important;
  }
}
</style>
